//
//  NSDictionary+Help.m
//  HDFramework
//
//  Created by haidong on 2016/10/17.
//  Copyright © 2016年 haidong. All rights reserved.
//

#import "NSDictionary+Help.h"

@implementation NSDictionary (Help)

- (NSString *)strForKey:(id)aKey {
    if ([self objectForKey:aKey] && ![[self objectForKey:aKey] isKindOfClass:[NSNull class]]) {
        return [self objectForKey:aKey];
    } else {
        return @"";
    }
}

- (NSArray *)arrForKey:(id)aKey {
    if ([self objectForKey:aKey] && ![[self objectForKey:aKey] isKindOfClass:[NSNull class]]) {
        return [self objectForKey:aKey];
    } else {
        return @[];
    }
}

- (NSDictionary *)dicForKey:(id)aKey {
    if ([self objectForKey:aKey] && ![[self objectForKey:aKey] isKindOfClass:[NSNull class]]) {
        return [self objectForKey:aKey];
    } else {
        return @{};
    }
}

#pragma mark -判断是否为空
- (NSString *)judgeisNSStringNull:(id)value returnValue:(id)returnvalue {
    NSString *string = [NSString stringWithFormat:@"%@",value];
    if (string == nil || string == NULL || [string isEqualToString:@"<null>"]|| [string isEqualToString:@"(null)"]) {
        return returnvalue;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return returnvalue;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
        return returnvalue;
    }
    return string;
}

@end
